<?php
/**
 * 当前聚会的留言情况
 */

namespace Meeting\Controller;
use Common\Controller\AdminbaseController;

class AdminMeetingCommentController extends AdminbaseController{

	protected $meeting_comment_model;
	function _initialize()
	{
		parent::_initialize();
		$this->meeting_comment_model = D("MeetingComment");
	}

	// 报名人的情况
	public function index(){

		$user_nicename = I('user_nicename');
		if($user_nicename){
			$where['user_nicename'] = array('like',"%$user_nicename%");
		}

		$comment_content = I('comment_content');
		if($comment_content){
			$where['comment_content'] = array('like',"%$comment_content%");
		}

		$db_prefix=C('DB_PREFIX');
		$count= $this->meeting_comment_model
			-> alias('a')
			-> field('a.*,b.user_nicename,c.meeting_title')
			-> join($db_prefix.'users b on a.user_id = b.id')
			-> join($db_prefix.'meeting c on a.meeting_id = c.meeting_id')
			-> where($where)
			-> count();

		// 分页
		$page = $this->page($count, 10);

		// 聚会评论人员列表
		$meeting_comment_list = $this->meeting_comment_model
			-> alias('a')
			-> field('a.*,b.user_nicename,c.meeting_title')
			-> join($db_prefix.'users b on a.user_id = b.id')
			-> join($db_prefix.'meeting c on a.meeting_id = c.meeting_id')
			-> where($where)
			-> order('a.comment_id desc')
			-> limit($page->firstRow, $page->listRows)
			-> select();

		$this->assign('meeting_comment_list',$meeting_comment_list); 	// 聚会参加的人
		$this -> assign("page", $page->show('Admin'));
		$this->display();
	}

	// 删除
	public function delete() {
		$comment_id = I('comment_id/d');
		$where['comment_id'] = $comment_id;
		$result = $this->meeting_comment_model->where($where)->delete();
		$data = array(
			'status' => $result ? true : false,
			'info' => $result ? '删除成功' : '删除失败，ID：'.$comment_id,
			'url' => '',
		);
		$this -> ajaxReturn($data);
	}

	/**
	 * 商品列表的批量操作
	 * @param string $type    处理类型 order排序
	 */
	public function indexBat($type='order') {
		if ($type == 'delete') {
			$ids = I('post.ids');
			if ($this->meeting_comment_model -> delete(implode(',',$ids)) !== FALSE) {
				$this -> success('删除成功');
			} else {
				$this -> error('删除失败');
			}

		}
	}
}